from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector

from wpez.items import WpezItem

class SixSpider(BaseSpider):
	name = "SixSpider"
	allowed_domains = ["360.cn"]
	#start_urls = ['http://tuan.360.cn/?pageno=1&city=bei_jing&price_sta=&price_end=#g']
	start_urls = ['http://tuan.360.cn/']
	
	def parse(self, response):
		hxs = HtmlXPathSelector(response)
		products = hxs.select('//div[contains(@class, "product-list")]')
		items = []
		for p in products:
			item = WpezItem()
			item['title'] = p.select('.//h3/a[contains(@class, "title")]/text()').extract()
			item['cover_image_url'] = p.select('.//div[contains(@class, "ad")]/a/img/@src').extract()
			item['url'] = p.select('.//h3/a[contains(@class, "title")]/@href').extract()
			item['price'] = p.select('.//div[contains(@class, "address")]/span[contains(@class, "price")]/text()').extract()
			item['value'] = p.select('.//div[contains(@class, "rebate")]/span[contains(@class, "price")]/text()')[0].extract()
			item['website'] = p.select('.//a[contains(@class, "site")]/text()').extract()
			item['site_url'] = p.select('.//a[contains(@class, "site")]/@href').extract()
			items.append(item)
		return items
